package com.cc.factory;

public class ObjectFacotry {
    //反射
    public static  Pig getPig(Class clazz) throws InstantiationException, IllegalAccessException {
        //return  new RedPig(12, "旺财");
        return (Pig) clazz.newInstance();
    }
    
    
    //稍微改进  
    public static  Pig getPig(String type) {
      //return  new RedPig(12, "旺财");
        if(type.equals("red")) {
            return new RedPig(12, "旺财");
        }else if(type.equals("black")) {
            new BlackPig(11, "来福");
        }else if(type.equals("yellow")) {
            new YellowPig(11, "来福");
        }
        return null;
  }
    
    //最low
//    public static  RedPig getRegPig() {
//        return  new RedPig(12, "旺财");
//    }
//    public static BlackPig getBlackPig() {
//        return  new BlackPig(11, "来福");
//    }
//    
//    public static YellowPig getYellowPig() {
//        return  new YellowPig(11, "来福");
//    }
    
    
}
